##%%%%%%%%%%%%%%%%%% rsqAANN.5_script.R %%%%%%%%%%%%%%%%%%%%%
## Script to run makeRsqMat0.1 in batch mode

library(Matrix)
library(MASS) ## For ginv() - Moore penrose inverse
## library(DAAG)
##%%%%%%%% Set Working Directory %%%%%%%%%%%%

setwd("D:/RWORK")

##%%%%%%%%%% Read in function files %%%%%%%%%

source("D:\\Desco\\Splus\\readCSV.ssc")
source("D:\\Desco\\Splus\\dataCleanFuncs.ssc")
source("D:\\Desco\\Splus\\lagM.ssc")
source("D:\\Desco\\Splus\\rowColFuncs.ssc")
source("D:/Desco/Splus/makeNormUnif.ssc")

source("D:/RWORK/simOfDemingFUNC.R")

j2z=junk2zero

##%%%%%% Load simulation data from disk %%%%%%%

 load("insL2");load("t1L2");load("t2L2")
 load("insL3");load("t1L3");load("t2L3")
 load("insL4");load("t1L4");load("t2L4")
 load("insL4S");load("t1L4S");load("t2L4S")
 load("insL7");load("t1L7");load("t2L7")
 load("insL7S");load("t1L7S");load("t2L7S")

##%%%%%%% Load in/out data sets previousely computed %%%%%%
load("Imat5");load("Imat2");load("Imat1");load("Imat.5")
load("Imat5Out");load("Imat2Out");load("Imat1Out");load("Imat.5Out")
load("Imat5.50Out");load("Imat2.50Out");load("Imat1.50Out");load("Imat.5.50Out")

##%%%%%%%%%%%% Run makeRsqMat %%%%%%%%%%%%%%%%%%%%%%%

## L7 N=500
# rsqA7t1N.5=makeRsqMatNcvAL(t1L7,insL7,Imat.5[,1:200],Imat.5Out[,1:200],Imat.5.50Out[,1:200])
# save(rsqA7t1N.5,file="rsqA7t1N.5")

# rsqA7t2N.5=makeRsqMatNcvAL(t2L7,insL7,Imat.5[,1:200],Imat.5Out[,1:200],Imat.5.50Out[,1:200])
# save(rsqA7t2N.5,file="rsqA7t2N.5")

## L7S N=500
rsqA7St1N.5=makeRsqMatNcvAL(t1L7S,insL7S,Imat.5[,1:200],Imat.5Out[,1:200],Imat.5.50Out[,1:200])
save(rsqA7St1N.5,file="rsqA7St1N.5")

rsqA7St2N.5=makeRsqMatNcvAL(t2L7S,insL7S,Imat.5[,1:200],Imat.5Out[,1:200],Imat.5.50Out[,1:200])
save(rsqA7St2N.5,file="rsqA7St2N.5") # run

## L4S N=500
# rsqA4St1N.5=makeRsqMatNcvAL(t1L4S,insL4S,Imat.5[,1:200],Imat.5Out[,1:200],Imat.5.50Out[,1:200])
# save(rsqA4St1N.5,file="rsqA4St1N.5") # run

# rsqA4St2N.5=makeRsqMatNcvAL(t2L4S,insL4S,Imat.5[,1:200],Imat.5Out[,1:200],Imat.5.50Out[,1:200])
# save(rsqA4St2N.5,file="rsqA4St2N.5") # run

## L4 N=500
# rsqA4t1N.5=makeRsqMatNcvAL(t1L4,insL4,Imat.5[,1:200],Imat.5Out[,1:200],Imat.5.50Out[,1:200])
# save(rsqA4t1N.5,file="rsqA4t1N.5")

# rsqA4t2N.5=makeRsqMatNcvAL(t2L4,insL4,Imat.5[,1:200],Imat.5Out[,1:200],Imat.5.50Out[,1:200])
# save(rsqA4t2N.5,file="rsqA4t2N.5")

## L3 N=500
# rsqA3t1N.5=makeRsqMatNcvAL(t1L3,insL3,Imat.5[,1:200],Imat.5Out[,1:200],Imat.5.50Out[,1:200])
# save(rsqA3t1N.5,file="rsqA3t1N.5")

# rsqA3t2N.5=makeRsqMatNcvAL(t2L3,insL3,Imat.5[,1:200],Imat.5Out[,1:200],Imat.5.50Out[,1:200])
# save(rsqA3t2N.5,file="rsqA3t2N.5")

## L2 N=500
rsqA2t1N.5=makeRsqMatNcvAL(t1L2,insL2,Imat.5[,1:200],Imat.5Out[,1:200],Imat.5.50Out[,1:200])
save(rsqA2t1N.5,file="rsqA2t1N.5")

rsqA2t2N.5=makeRsqMatNcvAL(t2L2,insL2,Imat.5[,1:200],Imat.5Out[,1:200],Imat.5.50Out[,1:200])
save(rsqA2t2N.5,file="rsqA2t2N.5")



q()
